{
LANG : PASCAL
PROB : stall4
}

program STALL4;
const
  fi = 'stall4.in';
  fo = 'stall4.out';
  max = 200;
var
  a : array[1..max, 1..max] of integer;
  c : array[1..max] of integer;
  mx, my, trace : array[1..max] of integer;
  n, m, res : integer;

procedure inp;
var
  i, j, k, s : integer;
begin
  read(n, m);
  fillchar(a, sizeof(a), false);
  for i := 1 to n do
  begin
    read(c[i]);
    for j := 1 to c[i] do
    begin
      read(k);
      a[i, j] := k;
    end;
  end;
end;

procedure init;
begin
  fillchar(mx, sizeof(mx), 0);
  fillchar(my, sizeof(my), 0);
end;

function timcapghep(x : integer) : integer;
var
  q : array[1..max] of integer;
  i, u, v, l, r : integer;
begin
  l := 1;
  r := 1;
  q[1] := x;
  fillchar(trace, sizeof(trace), 0);

  while l <= r do
  begin
    u := q[l];
    inc(l);
    for i := 1 to c[u] do
    begin
      v := a[u, i];
      if trace[v] = 0 then
      begin
        trace[v] := u;
        if my[v] = 0 then
        begin
          timcapghep := v;
          exit;
        end;
        inc(r);
        q[r] := my[v];
      end;
    end;
  end;
  timcapghep := 0;
end;

procedure tangcapghep(y : integer);
var
  x, nexty : integer;
begin
  inc(res);
  repeat
    x := trace[y];
    nexty := mx[x];
    mx[x] := y;
    my[y] := x;
    y := nexty;
  until y = 0;
end;

procedure process;
var
  x, y : integer;
begin
  res := 0;
  for x := 1 to n do
  begin
    y := timcapghep(x);
    if y > 0 then tangcapghep(y);
  end;
end;

procedure out;
begin
  writeln(res);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);

  inp;
  init;
  process;
  out;

  close(output);
  close(input);
end.